﻿@model Zor_Web.Models.Base.V_Zor_Certificate
@using Webdiyer.WebControls.Mvc;
@using Zor_Tools;
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>完税证管理</title>
    <link href="~/Content/LayerUI/src/css/layui.css" rel="stylesheet" />
    <link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <!-- Main -->
    <div class="layui-tab layui-tab-brief main-tab-container ">
        <div class="layui-tab-content">
            <button class="layui-btn layui-btn layui-btn-small addEditSelect" data-type="新增完税证"><i class="layui-icon">&#xe654;</i> 新 增 </button>
            <button class="layui-btn layui-btn-warm  layui-btn-small addEditSelect" data-type="编辑完税证"><i class="layui-icon">&#xe642;</i> 编 辑 </button>
            <button class="layui-btn layui-btn-danger  layui-btn-small deleteStop" data-type="删除完税证"><i class="layui-icon">&#xe640;</i> 删 除 </button>
            <button class="layui-btn layui-btn-danger layui-btn-small deleteStop" data-type="停用完税证"><i class="layui-icon">&#x1006;</i> 停用 </button>
            <button class="layui-btn layui-btn-normal layui-btn-small addEditSelect" data-type="查询"><i class="layui-icon">&#xe615;</i> 查询 </button>            
            <button class="layui-btn layui-btn-blue layui-btn-small allot" lay-submit lay-filter="replace"><i class="layui-icon">&#x1002;</i> 刷新 </button>
        </div>
        <div class="layui-tab-content ">
            <form class="layui-form">
                <table class="layui-table" lay-skin="line">
                    <thead>
                        <tr>
                            @*<th><input name="checkAll" lay-filter="checkAll" type="checkbox" lay-skin="primary"></th>*@
                            <th></th>
                            <th>启用人</th>
                            <th>启用街道办</th>
                            <th>起始完税证号</th>
                            <th>结束完税证号</th>
                            <th>当前完税证号</th>
                            <th>状态</th>
                            <th>字轨</th>
                            <th>填用</th>
                            <th>作废</th>
                            <th>结存</th>
                            <th>创建日期</th>
                        </tr>
                    </thead>
                    <tbody id="accordion">
                        @foreach (var item in Model.PageData)
                        {
                            <tr>
                                <td><input name="" lay-skin="primary" certificate-id="@item.Certificate_Id" certificate-collarman="@item.Certificate_CollarMan" certificate-starttaxnum="@item.Certificate_StartTaxNum" certificate-endtaxnum="@item.Certificate_EndTaxNum" certificate-zigui="@item.Certificate_Zigui" lay-filter="checkOne" type="checkbox"></td>
                                <td>@item.User_RealName</td>
                                <td>@item.Dt_Name</td>
                                <td>@item.Certificate_StartTaxNum</td>
                                <td>@item.Certificate_EndTaxNum</td>
                                <td>@item.Certificate_NowTaxNum</td>
                                <td>@item.Certificate_StateName</td>
                                <td>@item.Certificate_Zigui</td>
                                <td>@item.Certificate_FillIn</td>
                                <td>@item.Certificate_Invalid</td>
                                <td>@item.Certificate_Balance</td>
                                <td>@TimeHelper.TimeStampToDateTime(item.Certificate_CreateTime.ToString(), TimeHelper.ToTimeType.link_ymdt)</td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div class="row">
                    <div class="col-sm-9">
                        @Html.Pager(Model.PageData, new PagerOptions { PageIndexParameterName = "index", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "", @class = "pagination" })
                    </div>
                    <div class="col-sm-3">
                        共 @Model.PageData.TotalItemCount 条记录，页 @Model.PageData.CurrentPageIndex/@Model.PageData.TotalPageCount
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- Mode -->
    <div id="add_edit" style="display: none;padding: 20px;">
        <form class="layui-form">
            <div class=" layui-form-item" hidden>
                <label class="layui-form-label">ID：</label>
                <div class="layui-input-block">
                    <input type="text" id="Certificate_Id" autocomplete="off" placeholder="请输入ID" class="layui-input">
                </div>
            </div>
            <div class=" layui-form-item">
                <label class="layui-form-label">字轨：</label>
                <div class="layui-input-block ">
                    <input type="text" id="Certificate_Zigui" lay-verify="required" autocomplete="off" placeholder="请输入字轨" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label ">领用人：</label>
                <div class="layui-input-block ">
                    <select name="collarMan" class="form-control" id="Certificate_CollarMan" lay-verify="required">
                        <option value='0'></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">起始完税证号：</label>
                <div class="layui-input-block ">
                    <input type="text" id="Certificate_StartTaxNum" lay-verify="required" autocomplete="off" placeholder="请输入起始完税证号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束完税证号：</label>
                <div class="layui-input-block ">
                    <input type="text" id="Certificate_EndTaxNum" lay-verify="required" autocomplete="off" placeholder="请输入结束完税证号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="text-align: right;">
                <div class="layui-btn layui-btn-normal" lay-submit lay-filter="btnAddCertificate">提 交</div>
            </div>
        </form>
    </div>
    <!-- Mode 2-->
    <div id="select_certificate" style="display: none;padding: 20px;">
        <form class="layui-form">
            @using (Html.BeginForm("Zor_Certificate", "Base", new RouteValueDictionary { { "startDate", "" }, { "endDate", "" }, { "collarMan", "" }, { "State", "" } }, FormMethod.Post))
            {
                <div class=" layui-form-item">
                    <div class="layui-form-pane" style="margin-top: 15px;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">日期选择</label>
                            <div class="layui-input-inline">
                                <input class="layui-input startEndData" name="startDate" placeholder="开始日期" data-type="开始日期" id="startDate">
                            </div>
                            <div class="layui-input-inline">
                                <input class="layui-input startEndData" name="endDate" placeholder="截止日期" data-type="截止日期" id="endDate">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-pane" style="margin-top: 15px;">
                        <label class="layui-form-label">领用人</label>
                        <div class="layui-input-block">
                            <select name="collarMan" class="form-control" lay-verify="required" id="Certificate_CollarManSelect">
                                <option value='0' selected>全部</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-pane" style="margin-top: 15px;">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select name="State" class="form-control" id="Certificate_StateSelect" lay-verify="required">
                                <option value='4' selected>全部</option>
                                <option value='0'>未启用</option>
                                <option value='1'>已启用</option>
                                <option value='2'>已停用</option>
                                <option value='3'>已用完</option>
                            </select>
                        </div>
                    </div>
                </div>
                
                <div class="box-footer">
                    <button type="submit" class="btn btn-info pull-right"><i class="fa fa-search"></i>查询</button>                                   
                </div>                              
            }
        </form>
    </div>
    <!-- 框架必要 -->
    <script src="~/Content/Zor/Scripts/zor_base.js"></script>
    <script src="~/Content/LayerUI/src/layui.js"></script>
    <script type="text/javascript">
        var isMode = true;      //模态窗口1还是模态窗口2
        var zigui = "";
        var collarman = 0;
        var isAddAlter = true; //新增还是修改

        /**
         * 请求Ajax
         * 返回Json类型字符串
         * JSON.stringify({ 'foo': 'foovalue', 'bar': 'barvalue' }),  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
         */
        function JqPostSimpleData(url, postData, callBack) {
            layui.jquery.ajax({
                type: 'POST',
                url: url,
                contentType: 'application/json',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    callBack(data);
                }
            });
        }

        /**
         * 打开模态窗口方法
         */
        function JqOpen(jqType, jqArea, jqContent, callBack) {
            layer.open({
                title: jqType,
                type: 1,
                skin: 'layui-layer-rim',
                area: jqArea,
                content: jqContent,
                success: function () {
                    callBack();
                }
            });
        }

        /**
         *layui
         */
        layui.use(['element', 'layer', 'form', 'laydate'], function () {
            var element = layui.element()
            , jq = layui.jquery
            , form = layui.form()
            , laydate = layui.laydate;

            var start = {
                max: '2099-06-16 23:59:59'
              , istoday: false
              , choose: function (datas) {
                  end.min = datas;     //开始日选好后，重置结束日的最小日期
                  end.start = datas    //将结束日的初始值设定为开始日
              }
            };

            var end = {
                max: '2099-06-16 23:59:59'
              , istoday: false
              , choose: function (datas) {
                  start.max = datas;   //结束日选好后，重置开始日的最大日期
              }
            };
            jq('.startEndData').on('click', function () {
                var type = jq(this).data('type');
                if (type == "开始日期") {
                    start.elem = this;
                    laydate(start);
                }
                else {
                    end.elem = this
                    laydate(end);
                }
            })

            /**
             * 全选
             */
            form.on('checkbox(checkAll)', function (data) {
                if (data.elem.checked) {
                    jq("input[type='checkbox']").prop('checked', true);
                } else {
                    jq("input[type='checkbox']").prop('checked', false);
                }
                form.render('checkbox');
            });

            /**
             * 显示弹出框 - 增加、修改
             */
            jq('.addEditSelect').on('click', function () {
                var type = jq(this).data('type');
                var ary = check(jq);
                if (type == '查询') {
                    JqOpen(type, ['600px', '320px'], jq('#select_certificate'), function () {
                        jq("#startDate").val("");        //清空开始日期
                        jq("#endDate").val("");          //清空截止日期
                        isMode = false;                  //Mode2增加全部
                        GetStreetOffice();               //查询所有为3的街道

                    });
                    return;
                }
                if (type == '编辑完税证') {
                    if (ary.length > 1) {
                        layer.msg('一次只能编辑一条信息，请重新选择！');
                        return;
                    } else if (ary.length == 0) {
                        layer.msg('请选择要编辑的完税证信息！');
                        return;
                    }
                }
                isMode = true;
                GetStreetOffice();                       //查询所有为3的街道
                JqOpen(type, ['720px', '350px'], jq('#add_edit'), function () {
                    if (type == '编辑完税证') {
                        zigui = ary[0].Certificate_Zigui;//选中的值
                        collarman = ary[0].Certificate_CollarMan;
                        jq('#Certificate_Id').val(ary[0].Certificate_Id);
                        jq('#Certificate_StartTaxNum').val(ary[0].Certificate_StartTaxNum);
                        jq('#Certificate_EndTaxNum').val(ary[0].Certificate_EndTaxNum);
                        jq('#Certificate_Zigui').val(zigui);
                        isAddAlter = false;
                    }
                    else {
                        jq('#Certificate_Id').val('');
                        jq('#Certificate_StartTaxNum').val('');
                        jq('#Certificate_EndTaxNum').val('');
                        jq('#Certificate_Zigui').val('');
                        zigui = "";                      //初始化
                        isAddAlter = true;
                    }
                    jq("#Certificate_Zigui").focus();
                })
            })

            /**
             * 监听提交 - 增加
             */
            form.on('submit(btnAddCertificate)', function (data) {
                var jsonData = GetWebControls(add_edit, jq)
                loading = layer.load();  //显示加载
                JqPostSimpleData("/Base/AddZor_Certificate", JSON.stringify({ 'certificate': jsonData, 'oldZigui': zigui, 'isAddAlter': isAddAlter }), function (data) {
                    layer.close(loading);//关闭加载...
                    layer.msg(data.AnswerMeg, function () {
                        if (data.AnswerType == 1) {
                            Replace();
                        }
                    });
                });
            });

            /**
             * 监听提交 - 刷新
             */
            form.on('submit(replace)', function (data) {
                Replace();
            })

            /**
             * 监听提交 - 删除
             */
            jq('.deleteStop').on('click', function () {
                var type = jq(this).data('type');
                //判断是否有选项
                var ary = new Array();
                jq("input[lay-filter='checkOne']").each(function () {
                    if (jq(this).prop('checked')) {
                        var ckindex = jq(this).attr('certificate-id');
                        ary.push(ckindex);
                    }
                });
                if (type == "删除完税证") {
                    if (ary.length == 0) {
                        layer.msg('请选择要删除的完税证信息！');
                        return false;
                    }
                    //确认删除
                    layer.confirm("确定删除选中的完税证？", { icon: 2, btn: ['确定', '取消'] }, function (index, layero) {
                        loading = layer.load();
                        JqPostSimpleData('/Base/Delete_Certificate', JSON.stringify({ 'id': ary }), function (data) {
                            layer.close(loading);//关闭加载...
                            layer.msg(data.AnswerMeg, function () {
                                if (data.AnswerType == 1) {
                                    Replace();
                                }
                            });
                        });
                    });
                }
                else {
                    if (ary.length == 0) {
                        layer.msg('请选择要停用的完税证信息！');
                        return false;
                    }
                    //确认停用
                    layer.confirm("确定停用选中的完税证？", { icon: 2, btn: ['确定', '取消'] }, function (index, layero) {
                        loading = layer.load();
                        JqPostSimpleData('/Base/Stop_Certificate', JSON.stringify({ 'id': ary }), function (data) {
                            layer.close(loading);//关闭加载...
                            layer.msg(data.AnswerMeg, function () {
                                if (data.AnswerType == 1) {
                                    Replace();
                                }
                            });
                        });
                    });
                }
            });

            /*
             * 返回 选择行的值
             */
            function check() {
                var ary = new Array();
                jq("input[lay-filter='checkOne']").each(function () {
                    if (jq(this).prop('checked')) {
                        var ckindex = jq(this).attr('certificate-id');
                        var ckName = jq(this).attr('certificate-collarman');
                        var ckStartTaxNum = jq(this).attr('certificate-starttaxnum');
                        var ckEndTaxNum = jq(this).attr('certificate-endtaxnum');
                        var ckZiGui = jq(this).attr('certificate-zigui');
                        ary.push({ Certificate_Id: ckindex, Certificate_CollarMan: ckName, Certificate_StartTaxNum: ckStartTaxNum, Certificate_EndTaxNum: ckEndTaxNum, Certificate_Zigui: ckZiGui });
                    }
                });
                return ary;
            }

            /**
             * 查询所有为3的街道
             */
            function GetStreetOffice() {
                var html = "";
                if (!isMode) {
                    html = "<option value='0' selected>全部</option>";
                }
                JqPostSimpleData("/Base/GetStreetOffice", "", function (data) {
                    jq.each(data, function (i) {
                        html += "<option value='" + data[i].Dt_Id + "'>" + data[i].Dt_Name + "</option>";
                    });
                    jq("select[name='collarMan']").empty().append(html);
                    if (!isAddAlter) {
                        jq("select[name='collarMan']").val(collarman);
                    } else {
                        jq("select[name='collarMan']").val(jq('#Certificate_CollarMan option').val());//新增默认选中第一行
                    }
                    form.render('select');                                                            //刷新select选择框渲染
                })
            }
        })
    </script>
</body>
</html>
